package com.hd.crdao.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.base.MyBaseAdapter;
import com.hd.crdao.bean.PurchasedMealBean;
import com.hd.crdao.utils.UIUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/7/18 0018.
 *
 * 我购买的套餐的适配器
 */
public class PurchasedMealAdapter extends MyBaseAdapter<PurchasedMealBean.DataBean>{
    public PurchasedMealAdapter(List<PurchasedMealBean.DataBean> data) {
        super(data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(UIUtils.getContext(), R.layout.item_purchased_meal, null);
            //找到控件
            holder.mPrice = (TextView) convertView.findViewById(R.id.price);
            holder.mMeal = (TextView) convertView.findViewById(R.id.tv_meal);
            holder.mData = (TextView) convertView.findViewById(R.id.tv_data);
            holder.mUseCount = (TextView) convertView.findViewById(R.id.useCount);   //已使用
            holder.mResidueCount = (TextView) convertView.findViewById(R.id.residueCount);  //剩余
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }

        //设置数据
        PurchasedMealBean.DataBean dataBean = mDataSets.get(position);
        int sdAmount = dataBean.getServiceDetail().getSdAmount();   //套餐的价格
        String sdName = dataBean.getServiceDetail().getSdName();       //套餐的名字
        int sdTimes = dataBean.getServiceDetail().getSdTimes();        //套餐总共多少条
        int adTimes = dataBean.getAdTimes();   //剩余的的条数
        String adTerm = dataBean.getAdTerm();  //到期时间
        holder.mPrice.setText("￥"+sdAmount);
        holder.mMeal.setText(sdName);
        holder.mData.setText("有效期至:"+adTerm);
        holder.mUseCount.setText("已用"+(sdTimes-adTimes)+"条");
        holder.mResidueCount.setText("剩余"+adTimes+"条");
        return convertView;
    }

    class ViewHolder {
        TextView mPrice;
        TextView mMeal;
        TextView mData;
        TextView mUseCount;
        TextView mResidueCount;
    }
}
